#include <string.h>
#include <iostream>
using std::cout;
using std::endl;
class Stack{
public:
    Stack()
        :topIndex(-1){}
       bool empty(){//判断栈是否为空
          return topIndex == -1;
       }
       bool full(){//判断栈是否已经满了
          return topIndex == MAXSIZE -1;
       }
       void push(int value){//元素入栈
           if(full()){
               throw std::overflow_error("stack is full");
           }
           data[++topIndex] = value;
       }
       void pop(){//元素出栈
           if(empty()){
               throw std::underflow_error("stack is empty");
           }
           --topIndex;
       }
       int top(){//获取栈顶元素
           if(empty()){
               throw std::underflow_error("stack is empty");
           }
           return data[topIndex];
       }
private:
       static const int MAXSIZE = 100;
       int topIndex;
       int data[MAXSIZE];
};
void test(){
    Stack s;
    cout << "栈是否为空"  <<  ( (s.empty())? "是":"否") <<endl;
    s.push(10);
    cout<<"入栈10,栈顶元素"<<s.top()<<endl;
    s.push(20);
    cout<<"入栈20，栈顶元素"<<s.top()<<endl;

    s.pop();
    cout<<"出栈一次，栈顶元素"<<s.top()<<endl;

    cout<<"栈是否满了" <<  ( (s.full()) ? "是":"否") << endl;
}
int main()
{
    test();
    return 0;
}

